home *** CD-ROM | disk | FTP | other *** search
/ Floppyshop 2 / Floppyshop - 2.zip / Floppyshop - 2.iso / diskmags / 3565-4.665 / dmg-4385 / issue_10 / 18.pne < prev    next >
Text File  |  1987-04-21  |  12KB  |  252 lines

  1.  
  2.                    MISSING LINK TUTORIAL......PART 2
  3.  
  4.                                BY DEANO
  5.  
  6.   Hello again STOSSERS.  Welcome to the second part of the missing  link 
  7.   tutorial. This month we are going to look at the mapping commands.
  8.  
  9.    WORLD X1,Y1,X2,Y2,0,1
  10.    WORLD SCR,BLOCKS,MADR,X,Y,0
  11.    LANDSCAPE X1,Y1,X2,Y2,0,1
  12.    LANDSCAPE SCR,BLOCKS,MADR,X,Y,0
  13.    SETBLOCK MADR,X,Y,BLOCK
  14.    R=WHICH BLOCK(MADR,X,Y)
  15.    REPLACE BLOCKS MADR,BLOCK1,BLOCK2
  16.    R=BLOCK AMOUNT(MADR,BLOCK)
  17.    XY BLOCK MADR,XADR,YADR,BLOCK,NUM
  18.    X=X LIMIT(MADR,X1,X2)
  19.    Y=Y LIMIT(MADR,Y1,Y2)
  20.    A=MAP TOGGLE(MADR)
  21.  
  22.   These 'mapping' commands are used for scrolling the screen.  Note that 
  23.   you could use 'def scroll' for this purpose but these new command make 
  24.   scrolling a lot easier.  For a start,  scrolling left and right can be 
  25.   done in steps of less than 16 pixels thus creating smoothy  scrolling. 
  26.   It  also  solves the nightmare of moving sprites  across  a  scrolling 
  27.   background. Right.....lets look at the first command.
  28.  
  29.    WORLD,X1,Y1,X2,Y2,0,1
  30.  
  31.   The WORLD commands allow you to scroll the screen left, right, up, and 
  32.   down.  This  version of the command allows you to specify how much  of 
  33.   the screen you wish to use as the scrolling area.  This is usefull for 
  34.   having  the  top half of the screen as the  scrolling  area,  and  the 
  35.   bottom half as the games scoreboard.
  36.  
  37.   If you've seen how the STOS 'limit sprite' command works,  you'll  see 
  38.   that the mouse is limited to that part of the screen,  its like having 
  39.   it trapped in an invisible box.
  40.  
  41.   This is how this version of 'world' works.  It traps the scrolling map 
  42.   in  an  invisible box.  X1 and Y1 hold the start co=ordinates  of  the 
  43.   screen  area to be trapped...in other words the top left hand part  of 
  44.   the screen.  X2 and Y2 hold the end co-ordinates of the  box..IE:  the 
  45.   bottom right hand part of the screen.  The last two parameters have no 
  46.   meaning as yet so leave them as they are.
  47.  
  48.   In order to create these scrolling areas, known as maps. We first have 
  49.   to define one. We can do this using the EDDY program supplied with the 
  50.   missing  link  package.  This is simular to using  the  'Map  Definer' 
  51.   supplied with STOS only we don't use normal STOS sprites to create the 
  52.   map.  We use the MAKE program to make the sprites into world blocks so 
  53.   they  can be loaded into EDDY.  Note that even though the EDDY  manual 
  54.   tells us that we can load 'world' and 'landscape' blocks into the EDDY 
  55.   definer...we can only load 'world' blocks into it.  If I get time I'll 
  56.   do an article on these two programs.
  57.  
  58.    WORLD SCR,BLOCKS,MADR,X,Y,0
  59.  
  60.   This  is  the command that actually scrolls the map  we  defined  with 
  61.   EDDY.  Note that we need two sets of data installed before we can  use 
  62.   this command. These are...World Blocks, and Map Data.
  63.  
  64.     SCR=  This is the screen to display the map on,  it  can  be  either 
  65.     LOGIC, PHYSIC, or BACK.
  66.  
  67.     BLOCKS= This tells 'world' where our world blocks  are,  load  them 
  68.     into a memory bank and use 'start(bank-number)'. 
  69.  
  70.     MADR= The bank number of the map data saved from EDDY,  note it must 
  71.     have been saved as 'world data', again use 'start(bank-number)'.
  72.  
  73.     X and Y= The X and Y co-ordinates of the maps starting point.
  74.  
  75.   The nought does nothing as yet,  maybe in an update.  Anyway,  heres a 
  76.   routine that shows the use of the two commands.
  77.  
  78.    10 key off : hide : flash off : mode 0
  79.    20 load"BLOCK.MBK",5 : rem load world blocks into bank 5
  80.    30 load"MAP.MBK",6 : rem load world map data into bank 6
  81.    40 logic=back : X=0 : Y=0
  82.    45 world 32,10,288,190,0,1
  83.    50 repeat
  84.    60 world logic,start(5),start(6),X,Y,0
  85.    70 if jleft and X>0 then dec X
  86.    80 if jright and X<1500 then inc X
  87.    90 if jup and Y>0 then dec Y
  88.    100 if jdown and Y<2000 then inc Y
  89.    110 screen swap : wait vbl
  90.    120 until fire
  91.  
  92.   If we look at lines 80 and 100 we see that the program is checking  if 
  93.   the X and Y varibles are less than a number thats higher than the  co-
  94.   ordinates of the actual screen.  This is because the varibles are  the 
  95.   co-ordinates of the scrolling area of the map and not the screen.
  96.  
  97.   Note  that the first version of the WORLD command must have its X  co-
  98.   ordinates in steps of 16 pixels due to a bug in the ST's registers.
  99.  
  100.    The LANDSCAPE command....
  101.  
  102.   The LANDSCAPE command is exactly the same as WORLD except that it  can 
  103.   only  scroll its map in two directions.  Its only used for games  that 
  104.   scroll  just up and down.  It can't do the multi scrolling that  WORLD 
  105.   can do.  The parameters are the same as those of WORLD,  but the X co-
  106.   ordinate  cannot be changed in a loop,  only the Y co-ordinate.  X  is 
  107.   just used to set the X starting point of the map to be scrolled.
  108.  
  109.   Note,  as  with  the  first version of WORLD,  the  first  version  of 
  110.   LANDSCAPE  must have its X co-ordinates in steps of  16  pixels.  Note 
  111.   that we can use the last routine to see these commands in action. Just 
  112.   convert your sprites to LANDSCAPE blocks, load them into EDDY and make 
  113.   your  map making sure you don't go over the X co-ordinate of  304  and 
  114.   make  your map downwards,  not exceeding the 320 X  co-ordinate.  Save 
  115.   your map data as landscape data,  load your landscape blocks into bank 
  116.   five,  and new landscape map data in bank six.  Remove lines 80 and 90 
  117.   and run the program. As we can see, we can only move up and down.
  118.  
  119.   Note,  due to the bug in EDDY,  we have to make our sprites first into 
  120.   world blocks,  then landscape blocks.  Load the world blocks into EDDY 
  121.   to  make the landscape map,  then load the landscape blocks  into  our 
  122.   example routine. Bit of a pain but there we go.
  123.  
  124.    R=WHICH BLOCK(MADR,X,Y)
  125.  
  126.   As  you  may  have noticed,  we have being uses  these  things  called 
  127.   blocks,  ie:  converted sprites, to make the world and landscape maps. 
  128.   So we can now use this command as a form of collision  detection.  The 
  129.   MADR  varible holds the bank number of the map data used by the  world 
  130.   and landscape commands,  and X and Y are the co-ordinates of the block 
  131.   we're  checking  for.  R holds the block number.  So really  its  like 
  132.   checking  for a sprite entering a zone without having to set the  zone 
  133.   first. If we look at the screen in EDDY where we select our blocks, we 
  134.   can count along to a certain block to find its number in the row. Note 
  135.   that  the row starts from nought to the number of blocks in  the  row, 
  136.   just like the BOB command.  So, if we defined, say a diamond as sprite 
  137.   number one. This would be block number 0. 
  138.  
  139.   So what we want to do is place our diamond blocks in certain places of 
  140.   the map as we define it,  then tell STOS that when our BOB touches it, 
  141.   to detect a collision, add this line to our example.
  142.   
  143.    105 BL=which block (start(6),XBOB+14,YBOB+12)
  144.  
  145.   The  varibles XBOB and YBOB hold the X and Y co-ordinates of the  bob, 
  146.   as the bob touches a certain block,  the varible BL would contain  the 
  147.   row number of it. So, if the bob touched the diamond, then BL would be 
  148.   set  to nought.  If the bob touched the next block in the row then  BL 
  149.   would be set to one.  Lets say we defined two sprites has part of  the 
  150.   map,  and converted them to map blocks.  We could use this routine  to 
  151.   check which block has been touched. Try these lines...
  152.  
  153.    106 if BL=0 then print"You have found the diamond."
  154.    107 if BL=1 then print"You have hit the wall."
  155.  
  156.   Where the wall is the second block in the world/landscape blocks.
  157.  
  158.   SET BLOCK MADR,X,Y,BLOCK
  159.  
  160.   Each block in the map is set two either one if it exists, or nought if 
  161.   it does'nt.  These means that if a certain block was in the map at co-
  162.   ordinates  X  and Y,  it would be set to one, or nought  if  it was'nt 
  163.   there.  We can use this command with WHICH BLOCK to find a block, when 
  164.   its  found  we can set the block to nought which will then  erase  the 
  165.   found block off the screen. MADR is the bank number of the map data, X 
  166.   and Y is the co-ordinates to check at,  and BLOCK is the row number of 
  167.   the block to remove from screen. Example.....
  168.  
  169.    10 BL=which block(start(6),XBOB,YBOB)
  170.    20 if BL=1 then set block start(6),XBOB,YBOB,0 : bell
  171.  
  172.   REPLACE BLOCKS MADR,BLOCK1,BLOCK2
  173.  
  174.   This  command  does as it says....it replaces one type of  block  with 
  175.   another. This is usefull if say, you wanted to change all the diamonds 
  176.   on screen to money bags for example.  We can have our diamond block as 
  177.   block one in the row,  and the money block as block two,  then  change 
  178.   the diamonds into money bags like so....
  179.  
  180.    100 replace blocks start(6),1,2
  181.  
  182.   R=BLOCK AMOUNT(MADR,BLOCK)
  183.  
  184.   This  command is usefull for checking how many times a  certain  block 
  185.   appears in a map.  If we had our diamond and money bag blocks still in 
  186.   the same place, and we put 20 copies of our diamond on the map screen, 
  187.   then  we  could  use this command to find how  many  diamonds  are  on 
  188.   screen. Try this example.....
  189.  
  190.    100 DIAMONDS=block amount(start(6),1)
  191.    110 if DIAMONDS=0 then print"All diamonds are collected"
  192.  
  193.   So,  BLOCK holds the number of block ones..(diamonds) there are in the 
  194.   map.  As each one is removed with SET BLOCK, the DIAMONDS varible will 
  195.   decrease by one, line 110 checks if all diamonds have gone.
  196.  
  197.    XY BLOCK MADR,XADR,YADR,BLOCK,NUMBER
  198.  
  199.   If we wanted to store all the X and Y co-ordinates of a certain  block 
  200.   in an array....this command will do it. So, if we wanted to set  the X 
  201.   and  Y  co-ordinates of the diamond...(block 1),  we  would  use  this 
  202.   little routine....
  203.  
  204.    10 A=block amount(start(6),1)
  205.    20 dim XBL(A),YBL(A)
  206.    30 xy block start(6),varptr(XBL(0)),varptr(YBL(0)),1,A
  207.    40 for X=0 to A : print XBL(X),YBL(X) : next X
  208.  
  209.   XADR and YADR are the X and Y arrays to put the co-ordinates in, BLOCK 
  210.   is the row number of the block we want to get the co-ordinates of, and  
  211.   NUMBER is the total number of block ones found in the map.
  212.  
  213.   This  can be used if you had a number of diamonds and you wanted  each 
  214.   one  to  score different points.  Using the arrays you can  see  which 
  215.   diamond block has been collected and update the score with the certain 
  216.   diamonds points....like so
  217.  
  218.   50 if A=1 and XBOB=XBL(1) then SC=SC+40
  219.   60 if A=1 and YBOB=YBL(4) then SC=SC+100
  220.  
  221.   X=X LIMIT(MADR,X1,X2)
  222.   Y=Y LIMIT(MADR,Y1,Y2)
  223.  
  224.   These  commands imform STOS how large in width and height the map  is. 
  225.   X1 is the X start of the map,  X2 is the X end of the map, Y1 is the Y 
  226.   start of the map, and Y2 is the Y end of the map. X and Y hold the end 
  227.   co-ordinates of the map. MADR is the bank number of the map data. This 
  228.   can be used to check if a bob is still within the X and Y areas.
  229.  
  230.   M=MAP TOGGLE(MADR)
  231.  
  232.   A nice simple one here.  If the data in MADR is world data,  then this 
  233.   command will convert it to landscape data, or vise versa...
  234.  
  235.    10 load"map.mbk",6 : rem World data
  236.    20 N=map toggle(start(6))
  237.    30 print"The world data is now landscape data"
  238.    40 N=map toggle(start(6))
  239.    50 print"The landscape data is now back to world data"
  240.  
  241.   This  is  usefull  if you had some levels in your game  that  use  the 
  242.   landscape command, and some that used 'world'.
  243.  
  244.   Well  thats the end of part 2,  see you in part 3 next month where  we 
  245.   shall have a look at the text commands.
  246.  
  247.  
  248.   
  249.  
  250.  
  251.  
  252.